
toBase2 x = toBase2' x (floor $ logBase 2 (fromIntegral x))
toBase2' :: Int -> Int -> String
toBase2' _ (-1) = []
toBase2' x exp
               | exp < 0 = error $ "exponant should not be negative: x=" ++ show x
               | x >= result  = '1': toBase2' (x - result) (exp-1)
               | otherwise    = '0': toBase2' x (exp-1) 
                 where result = 2^exp

isPalindromeBase2 x
                  | normal == reversed = True
                  | otherwise = False
                    where normal = toBase2 x
                          reversed = reverse normal

isPalindromeBase10 x
                  | str == reverse str = True
                  | otherwise = False
                    where str = show x

main = sum [x | x <- [1..999999], isPalindromeBase10 x, isPalindromeBase2 x]